package com.dm.cloud.images.controller;

import com.dm.cloud.core.mode.ResultModel;
import com.dm.cloud.images.mode.NetworkCreatMode;
import com.dm.cloud.images.mode.NetworkDetail;
import com.dm.cloud.images.service.NetworkService;
import com.dm.cloud.oauthlib.service.anon.HasLogin;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/apis/v1/imageServer")
@Tag(name =  "容器网络管理")
@HasLogin
public class NetworkController {

    @Autowired
    private NetworkService networkService;

    @GetMapping("list")
    @Operation(summary = "所有容器网络列表")
    public ResultModel<List<NetworkDetail>> list(
            @Parameter(description = "名称",in = ParameterIn.QUERY) String name,
            @Parameter(description = "节点ID",in = ParameterIn.QUERY) String nodeId
    ) {
        return ResultModel.success(networkService.list(name,nodeId));
    }

    @PostMapping("create")
    @Operation(summary = "创建网络")
    public ResultModel<NetworkDetail> create(@RequestBody NetworkCreatMode creatMode){
        return ResultModel.success(networkService.create(creatMode));
    }

    @DeleteMapping("delete")
    @Operation(summary = "删除网络")
    public ResultModel<Boolean> delete(@Parameter(in = ParameterIn.QUERY,description = "节点ID") String nodeId
            ,@Parameter(in = ParameterIn.QUERY,description = "网络ID") String networkId){
        return ResultModel.success(networkService.delete(nodeId,networkId));
    }

}
